package com.winshare.saleAssistant.controller;

import com.winshare.saleAssistant.domain.dto.req.AreaCreateDTO;
import com.winshare.saleAssistant.domain.dto.req.AreaDeleteDTO;
import com.winshare.saleAssistant.domain.dto.req.AreaUpdateDTO;
import com.winshare.saleAssistant.service.AreaService;
import com.winshare.saleAssistant.util.LogicResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/area")
@CrossOrigin
@Api(value = "区域信息", description = "区域信息")
public class AreaController {

    private final AreaService areaService;

    public AreaController(AreaService areaService) {
        this.areaService = areaService;
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增区域接口",notes = "新增区域接口")
    public LogicResponse save(@RequestBody @Validated AreaCreateDTO areaCreateDTO) {
        areaService.save(areaCreateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改区域接口",notes = "修改区域接口")
    public LogicResponse update(@RequestBody @Validated AreaUpdateDTO areaUpdateDTO) {
        areaService.update(areaUpdateDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除区域接口",notes = "删除区域接口")
    public LogicResponse delete(@RequestBody @Validated AreaDeleteDTO areaDeleteDTO) {
        areaService.delete(areaDeleteDTO);
        return LogicResponse.success("success");
    }

    @PostMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询区域列表接口",notes = "查询区域列表接口")
    public LogicResponse queryAreaList() {
        return LogicResponse.success(areaService.getAreaList());
    }
}
